package com.apes.fn.business.insurance.repository;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.apes.framework.query.ApesDao;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
 * @program: apes-server
 * @description 保险销售报表
 * @author: czs
 * @create: 2021-08-18 16:32
 **/
@Component
public class InsuranceReportDao extends ApesDao {
    /**
     * 获取销售提成
     * @param param
     * @return
     */
    public JSONArray findInsuranceCommission (JSONObject param) {
        String sql = "SELECT (CASE WHEN SUM(FN_PROFIT) IS NULL THEN 0 ELSE SUM(FN_PROFIT) END) FN_PROFIT\n" +
                "FROM TC_CXTC\n" +
                "WHERE SALESMAN_ID = :sales\n" +
                "AND TJRQ >=:start\n" +
                "AND TJRQ <=:end";
        return toJSONArray(find(sql, param));
    }

    /**
     * 获取门店销售提成
     * @param param
     * @return
     */
    public JSONArray findDeptInsuranceCommission (JSONObject param) {
        String sql = "SELECT (CASE WHEN SUM(FN_PROFIT) IS NULL THEN 0 ELSE SUM(FN_PROFIT) END) FN_PROFIT\n" +
                "FROM TC_CXTC\n" +
                "WHERE DEPT_ID = :dept\n" +
                "AND TJRQ >=:start\n" +
                "AND TJRQ <=:end";
        return toJSONArray(find(sql, param));
    }
}
